﻿using System;
using System.Xml.Linq;

namespace YArchitech.Temp
{
	public class HYAccessory : HYMEPObject, IHYXmlSerial
	{
		public double Coefficient { get; set; }

		public double ShockResistance { get; set; }

		public IHYSpecification InPort
		{
			get
			{
				return this.m_InPort;
			}
			set
			{
				this.m_InPort = value;
			}
		}

		public HYAccessory()
		{
			base.Name = "附件";
			this.m_HostPipeline = null;
			this.Coefficient = 0.0;
		}

		public override void ReadXml(XElement xe)
		{
			base.ReadXml(xe);
			this.Coefficient = xe.GetDoubleAttribute("Cofficient", 0.0);
		}

		public override void WriteXml(XElement xe)
		{
			base.WriteXml(xe);
			xe.SetAttributeValue("Cofficient", this.Coefficient);
		}

		public override void SetNext(HYMEPObject nextObj)
		{
			base.SetNext(nextObj);
			if (nextObj is HYPipeline)
			{
				this.m_HostPipeline = (nextObj as HYPipeline);
			}
		}

		public virtual HYPipeline GetHostPipeline()
		{
			if (this.m_HostPipeline != null)
			{
				return this.m_HostPipeline;
			}
			HYMEPObject previous = base.Previous;
			while (previous != null && !(previous is HYPipeline))
			{
				previous = previous.Previous;
			}
			if (previous == null)
			{
				return null;
			}
			this.m_HostPipeline = (previous as HYPipeline);
			return this.m_HostPipeline;
		}

		public virtual void CalCoefficient()
		{
		}

		public override void Cal(HYSystemOption option)
		{
			this.CalCoefficient();
			HYPipeline hostPipeline = this.GetHostPipeline();
			if (hostPipeline != null)
			{
				hostPipeline.AddAttachedObject(this, base.Name, this.ShockResistance, true, 0);
			}
		}

		protected HYPipeline m_HostPipeline;

		protected IHYSpecification m_InPort;
	}
}
